package com.wangsd.web.weixin.controller;

import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import com.wangsd.common.entity.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 微信支付controller
 */
@Slf4j
@RestController
@RequestMapping("/api/pay")
public class WechatPayController {

    public Object wechatNativePay(boolean sandboxEnv, String mchId, String appId, String mchKey, String subMchId, WxPayUnifiedOrderRequest request) {
        if (StringUtils.isBlank(mchId)) {
            return Result.fail("mchId不能为空");
        }
        if (StringUtils.isBlank(mchId)) {
            return Result.fail("appId不能为空");
        }
        if (StringUtils.isBlank(mchId)) {
            return Result.fail("mchKey不能为空");
        }
        if (sandboxEnv) {
            if (StringUtils.isBlank(subMchId)) {
                return Result.fail("subMchId不能为空");
            }
        }
        WxPayConfig payConfig = new WxPayConfig();
        payConfig.setAppId(mchId);
        payConfig.setMchId(appId);
        payConfig.setMchKey(mchKey);

        // 可以指定是否使用沙箱环境
        payConfig.setUseSandboxEnv(sandboxEnv);

        WxPayService wxPayService = new WxPayServiceImpl();
        return null;
    }
}
